//
// Created by 王书哲 on 25-3-18.投色子模拟程序 与 manydice.c一起编译
//
#include "diceroll.h"
#include <stdio.h>
#include <stdlib.h>

int roll_count = 0;
//生成随机数
static int rollem(int sides)
{
    int roll;
    roll = rand() % sides + 1;
    ++roll_count;
    return roll;
}
//投 dice个 sides面色子
int roll_n_dice(int dice, int sides)
{
    //色子总数
    int total = 0;
    if (sides < 2)
    {
        printf("Need at least 2 sides.\n");
        return -2;
    }
    if (dice < 1)
    {
        printf("Need at least 1 sides.\n");
        return  -1;
    }
    for (int i = 0; i <dice; i++) {
        total += rollem(sides);
    }
    return total;
}